package zmee.wchn;

import com.kingdee.util.StringUtils;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.servicehelper.operation.SaveServiceHelper;

public class ProjectInitiationAdultBillname extends AbstractOperationServicePlugIn {
    @Override
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
        super.afterExecuteOperationTransaction(e);
        DynamicObject[] dataEntities = e.getDataEntities();
        for (DynamicObject dynamicObject: dataEntities) {
            //取项目立项名称
            String billname = dynamicObject.getString("billname");
            //取项目名称
            DynamicObject pro = (DynamicObject) dynamicObject.get("pro");

            String proname = pro.getString("name");
            //如果项目名称不等于项目立项名称
            if (!StringUtils.equals(billname,proname)){
                //修改项目名称为项目立项名称
                pro.set("name",billname);
                SaveServiceHelper.update(pro, OperateOption.create());
            }
        }
    }

    @Override
    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
        super.beforeExecuteOperationTransaction(e);
        DynamicObject[] dataEntities = e.getDataEntities();
        for (DynamicObject dynamicObject: dataEntities) {
            //取项目立项名称
            String billname = dynamicObject.getString("billname");
            //取项目名称
            DynamicObject pro = (DynamicObject) dynamicObject.get("pro");

            String proname = pro.getString("name");
            //如果项目名称不等于项目立项名称
            if (!StringUtils.equals(billname,proname)){
                //修改项目名称为项目立项名称
                pro.set("name",billname);
                SaveServiceHelper.update(pro, OperateOption.create());
            }
        }
    }
}
